function cell = keygen(N,imin,imax,char,prob)

    cell = {};
    lenChar = length(char);
    
%validar args
    if nargin < 4
        error('wrong number of inputs')
    
    elseif nargin == 4
        prob(1,1:lenChar) = 0.5;
   
    else 
        lenProb = length(prob);
        if lenProb ~= lenChar
           error("Probability and Character array lengths don't match")
        end
    end
    
   
 %criar keys

    for k = 1 : N
        lenKey = randi([imin,imax]);
        key = randsample(char,lenKey,true,prob);
        cell{k} = key;
      
        noDupe = unique(cell);

    %caso seja duplicado
       if numel(cell) ~= numel(noDupe)
            key = randsample(char,lenKey,true,prob);
           cell{k} = key;
           k = k-1;
       end

    end

end




